<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Background
 *
 * @author tuancasi
 */
class Background extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return User the static model class
     */
    public static function model($className = __CLASS__) {
	return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
	return '{{backgrounds}}';
    }

    public function rules() {
	return array(
	    array('background_id, name', 'safe')
	);
    }

    public static function getAllBackground($type) {
	$aImg = Yii::app()->db->createCommand("SELECT * FROM {{backgrounds}} WHERE type='" . $type . "'")->queryAll();
	return $aImg;
    }

    public static function addBackground($name, $type) {
	Yii::app()->db->createCommand("INSERT INTO `{{backgrounds}}`(`type`, `name`, `time_created`) VALUES('" . $type . "','" . $name . "', " . CURR_TIME . ")")->execute();
    }

    public static function deleteImg($name) {
	Yii::app()->db->createCommand("DELETE FROM {{backgrounds}} WHERE name = '" . $name . "'")->execute();
    }

}

?>
